﻿using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using DHISInteroperability.Authentication;
using DHISInteroperability.SystemInformation;

namespace DHISInteroperability.Tests
{
    [TestClass]
    public class DHIS2SystemTest
    {
        [TestMethod]
        public void Retrieving_System_Info()
        {
            AuthorizationAgent agent = new AuthorizationAgent("admin", "district");
            var baseUrl = "https://apps.dhis2.org/demo";

            var system = new DHIS2System(baseUrl, agent);
            var info = system.GetInfo();

            Assert.IsNotNull(info, "DHIS System Information could not be retrieved");
            Assert.AreEqual(baseUrl, info.contextPath, "System path is invalid");
        }

        [TestMethod]
        public void Connection_To_DHIS2()
        {
            Assert.Inconclusive("Technical problem with establishing request or API related");
            AuthorizationAgent agent = new AuthorizationAgent("admin", "district");
            var baseUrl = "https://apps.dhis2.org/demo";

            var system = new DHIS2System(baseUrl, agent);
            var bActual = system.Ping();

            Assert.IsTrue(bActual, "DHIS - Authorization failed");
        }

        [TestMethod]
        public void DHIS2_System_Context()
        {
            AuthorizationAgent agent = new AuthorizationAgent("admin", "district");
            var baseUrl = "https://apps.dhis2.org/demo";

            var system = new DHIS2System(baseUrl, agent);
            var context = system.GetContext();

            Assert.IsNotNull(context, "DHIS System Information could not be retrieved");
            Assert.AreEqual(baseUrl, context.contextPath, "System path is invalid");
        }
    }
}
